package com.mswordutil.markdown.builder;

import com.mswordutil.markdown.Block;
import com.mswordutil.markdown.BlockType;
import com.mswordutil.markdown.MDToken;
import com.mswordutil.markdown.ValuePart;

public class ImageBuilder implements BlockBuilder{

	private String content;
//	private String title;
	private String url;
//	private String alt;
	public ImageBuilder(String content){
		this.content = content;
	}
	
	public Block bulid() {
		Block block = new Block();
		block.setType(BlockType.IMG);
		block.setValueParts(new ValuePart(url));
		return block;
	}

	public boolean isRightType() {
		int i = content.indexOf(MDToken.IMG);
		int j = content.indexOf("]", i);
		if(j>0){
			int k = content.indexOf("(", j);
			if(k>0&&k==(j+1)){
				int l = content.indexOf(")", k);
				if(l>0){
					int m = content.indexOf(" ", k);
					int urlEnd = (m>k && m<l)?m:l;
					url = content.substring(k+1, urlEnd);
					return true;
				}
			}
		}
		return false;
	}

}
